package demo05

/**
 * @author xiaoZhao
 * @date 2022/6/30
 * @describe
 *          Java中的属性是静态绑定的，方法是在运行时动态绑定的
 *          Scala 中的属性和方法都是动态绑定的
 *          Scala中的类也是单继承的
 */
object Test07_Inherit {
  def main(args: Array[String]): Unit = {
    val student7 = new Student7("wangba", 23)
    val student8 = new Student7("wangba", 23,"12121212")
    student8.printInfo()


    def personInfo(person: Person7): Unit ={
      person.printInfo()
    }

    println("=======================")
    val teacher = new Teacher()
    val person = new Person7()
    personInfo(student7)
    personInfo(teacher)
    personInfo(person)

  }
}

class Person7(){
  var name: String = _
  var age: Int = _
  println("1.父类的主构造器调用")

  def this(name: String,age: Int){
    this()
    println("2.父类的辅助构造器被调用")
    this.name = name
    this.age = age
  }

  def printInfo(): Unit ={
    println(s"Person: $name  $age")
  }
}
// 默认调用Person7的无参主构造器
class Student7(name: String,age: Int) extends Person7(name ,age ){
  var stuNo: String = _
  println("3.子类的主构造器调用")

  def this(name: String,age: Int,stuNo: String){
    this(name,age)
    this.stuNo = stuNo
    println("4.子类的辅助构造器调用")
  }

  // 重写父类的方法
  override def printInfo(): Unit = {
    println(s"Student: $name  $age $stuNo")
  }
}

class Teacher extends Person7{
  override def printInfo(): Unit = {
    println(s"Teacher")
  }
}